package cn.mrcode.fd.blog.controller;

import cn.mrcode.fd.blog.cache.service.IArticleCache;
import cn.mrcode.fd.blog.cache.service.IUserCache;
import cn.mrcode.fd.blog.common.BaseController;
import cn.mrcode.fd.blog.services.IArticleService;
import cn.mrcode.fd.blog.services.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author zhuqiang
 * @version V1.0
 * @date 2015/12/2 20:42
 */
@Controller
public class SysController extends BaseController {
    @Autowired
    private IUserService iUserService;
    @Autowired
    private IArticleService iArticleService;
    @Autowired
    private IArticleCache iArticleCache;
    @Autowired
    private IUserCache iUserCache;

    /**
     * 首页
     * @param model
     * @return
     */
    @RequestMapping("/")
    public String index(Model model) throws Exception {
//        List<UserCu> recUsers = iUserService.getRecUser(6); //获取推荐用户
//        List<ArticleCu> topArticles = iArticleService.top(6);

        model.addAttribute("topUsersTotal", iUserCache.getTotalTop(0,5,1));
        model.addAttribute("topUsersToday", iUserCache.getTodayTop(0,5,1));
        model.addAttribute("topArticles", iArticleCache.getAllTop(0,5,1));
        model.addAttribute("weekNewestArticles", iArticleCache.getWeekNewests(0,5,1));
        model.addAttribute("weekHotTopsArticles", iArticleCache.getWeekHotTops(0,5,1));

//
        return "/index";
    }


    @RequestMapping("/blog/hot/total")
    public String topUsersTotal(Model model,Integer pageNo) throws Exception {
        pageNo = pageNo == null? 1:pageNo;
/*        Page<UserCu> page = new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(9);*/
//        List<UserCu> users = iUserService.getAllUser(page); //获取推荐用户
        model.addAttribute("usersPage", iUserCache.getMoreTotalTop(pageNo, 9));
        return "/user/user_hotTopTotal";
    }
    @RequestMapping("/blog/hot/today")
    public String topUsersToday(Model model,Integer pageNo) throws Exception {
        pageNo = pageNo == null? 1:pageNo;
/*        Page<UserCu> page = new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(9);*/
//        List<UserCu> users = iUserService.getAllUser(page); //获取推荐用户
        model.addAttribute("usersPage", iUserCache.getMoreTodayTop(pageNo, 9));
        return "/user/user_hotTopToday";
    }
}
